import inspect

from django.contrib import admin

from main import models

# Register your models here.


from django.contrib import admin
from django.contrib.auth.admin import UserAdmin
from django.contrib.auth.models import User
from django.utils.translation import gettext_lazy as _


class UserAdmin1(UserAdmin):
    fieldsets = (
        (None, {"fields": ("username", "password")}),
        (_("Personal info"), {"fields": ("first_name", "last_name", "email")}),
        (
            _("Permissions"),
            {
                "fields": (
                    "is_active",
                    "is_staff",
                    "is_superuser",
                    "groups",
                    "user_permissions",
                ),
            },
        ),
        (_("Important dates"), {"fields": ("last_login", "date_joined")}),
        ('extra', {'fields':('remark','avatar','operator_name','delete_time')})
    )


# Re-register UserAdmin
admin.site.unregister(User)
admin.site.register(User, UserAdmin1)

for attr in dir(models):
    model = getattr(models, attr)
    if not inspect.isclass(model):
        continue

    try:
        admin.site.register(model, admin.ModelAdmin)
    except Exception as _:  # noqa
        pass
